<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>
          <a-col>
            <a-form-model-item label='计划' prop='coursePlanId'>
              <s-dict-select-tag style='overflow-y: scroll;height: 55px' v-model='queryParam.coursePlanId' placeholder='请选择计划'
                                 dictCode='cou_course_plan,course_plan_name,id' />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter='24'>
          <a-col>
            <a-form-model-item label='关联对象类型' prop='relObjTtype'>
              <s-dict-select-tag v-model='queryParam.relObjTtype' placeholder='选择关联对象类型'
                                 dictCode='course_target_obj_ttype' />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter='24' style='height: 75px'>
          <a-col>
            <a-form-model-item label='目标对象' prop='relObjId'>
              <s-dict-select-tag style='overflow-y: scroll;height: 70px' v-model='queryParam.relObjId' placeholder='请选择目标对象'
                                 dictCode='cou_subject,subject_name,id' />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter='24' v-if='toggleSearchStatus'>
          <a-col :span='12'>
            <a-form-model-item label='计划执行状态' prop='courPlanExecStatus'>
              <s-dict-select-tag v-model='queryParam.courPlanExecStatus' placeholder='选择计划执行状态'
                                 dictCode='cour_plan_exec_status' />
            </a-form-model-item>
          </a-col>
          <a-col :span='6'>
            <a-form-model-item label='启用状态'>
              <s-dict-select-tag v-model='queryParam.izOpen'
                                 dictCode='iz_open' placeholder='选择是否启用状态' />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter='24'>
          <a-col :offset='8'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button @click='handleAdd' type='primary' icon='plus'>新增</a-button>
      <a-button type='primary' icon='download' @click="handleExportXls('rel_course_plan_app')">导出</a-button>
      <a-upload name='file' :showUploadList='false' :multiple='false' :headers='tokenHeader' :action='importExcelUrl'
                @change='handleImportExcel'>
        <a-button type='primary' icon='import'>导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList='superFieldList' ref='superQueryModal'
                     @handleSuperQuery='handleSuperQuery'></j-super-query>
      <a-dropdown v-if='selectedRowKeys.length > 0'>
        <a-menu slot='overlay'>
          <a-menu-item key='1' @click='batchDel'>
            <a-icon type='delete' />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style='margin-left: 8px'> 批量操作
          <a-icon type='down' />
        </a-button>
      </a-dropdown>
      <template>
        <span style="float:right;">
          <a @click="searchQuery()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <a-button v-print="'#datatable'" ghost type="primary">打印</a-button>
        </span>
      </template>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a
        style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>

      <a-table
        id="datatable"
        ref='table'
        size='middle'
        :scroll='{x:true}'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        class='j-table-force-nowrap'
        @change='handleTableChange'>

        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='imgSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button
            v-else
            :ghost='true'
            type='primary'
            icon='download'
            size='small'
            @click='downloadFile(text)'>
            下载
          </a-button>
        </template>

        <span slot='action' slot-scope='text, record'>
          <a @click='handleEdit(record)'>编辑</a>

          <a-divider type='vertical' />
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a @click='handleDetail(record)'>详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <rel-course-plan-app-modal ref='modalForm' @ok='modalFormOk'></rel-course-plan-app-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import RelCoursePlanAppModal from './modules/RelCoursePlanAppModal'
import { getAction, deleteAction, postAction } from '@api/manage'

export default {
  name: 'RelCoursePlanAppList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    RelCoursePlanAppModal
  },
  data() {
    return {
      description: 'rel_course_plan_app管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        // {
        //   title:'计划id',
        //   align:"center",
        //   dataIndex: 'coursePlanId'
        // },
        {
          title: '计划名称',
          align: 'center',
          dataIndex: 'coursePlanAppName'
        },
        // {
        //   title:'目标对象',
        //   align:"center",
        //   dataIndex: 'relObjId'
        // },
        {
          title: '目标对象名称',
          align: 'center',
          dataIndex: 'objectName'
        },
        {
          title: '关联对象类型',
          align: 'center',
          dataIndex: 'relObjTtype_dictText'
        },
        // {
        //   title:'关联对象类型英文名称',
        //   align:"center",
        //   dataIndex: 'relObjNameEn_dictText'
        // },
        // {
        //   title:'关联对象类型中文名称',
        //   align:"center",
        //   dataIndex: 'relObjNameCn_dictText'
        // },
        {
          title: '计划执行状态',
          align: 'center',
          dataIndex: 'courPlanExecStatus_dictText'
        },
        {
          title: '是否有效',
          align: 'center',
          dataIndex: 'izOpen_dictText'
        },
        {
          title: '是否删除',
          align: 'center',
          dataIndex: 'izDelete_dictText'
        },
        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createUserId'
        },
        {
          title: '创建时间',
          align: 'center',
          sorter: true,
          dataIndex: 'createTime',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/relcourseplanapp/relCoursePlanApp/list',
        delete: '/relcourseplanapp/relCoursePlanApp/delete',
        deleteBatch: '/relcourseplanapp/relCoursePlanApp/deleteBatch',
        exportXlsUrl: '/relcourseplanapp/relCoursePlanApp/exportXls',
        importExcelUrl: 'relcourseplanapp/relCoursePlanApp/importExcel'

      },
      dictOptions: {},
      superFieldList: []

    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'coursePlanId', text: '计划id', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'relObjId',
        text: '目标对象id(班级id(默认)，学生id，老师id，科目id)，表示该课表应用对象编码',
        dictCode: ''
      })
      fieldList.push({
        type: 'int',
        value: 'relObjTtype',
        text: '关联对象类型(1:班级(默认);2教室场地 3.老师;4.科目 5:学生;)',
        dictCode: ''
      })
      fieldList.push({
        type: 'string',
        value: 'relObjNameEn',
        text: '关联对象类型英文名称（班级cou_class、教室fac_classroom、老师tea_teacher、科目cou_subject、学生stu_student）',
        dictCode: ''
      })
      fieldList.push({
        type: 'string',
        value: 'relObjNameCn',
        text: '关联对象类型中文名称（班级cou_class、教室fac_classroom、老师tea_teacher、科目cou_subject、学生stu_student）',
        dictCode: ''
      })
      fieldList.push({ type: 'int', value: 'courPlanExecStatus', text: '计划执行状态（1待执行，2已执行，3再次执行，4废除不执行）', dictCode: '' })
      fieldList.push({ type: 'int', value: 'izOpen', text: '是否有效（0否无效，1是有效）', dictCode: 'iz_open,,' })
      fieldList.push({ type: 'int', value: 'izDelete', text: '是否删除（0否，1是已删除）', dictCode: 'iz_delete,,' })
      fieldList.push({ type: 'string', value: 'createUserId', text: '创建人(计划下达人）', dictCode: '' })
      fieldList.push({ type: 'date', value: 'createTime', text: '创建时间(计划下达时间）' })
      fieldList.push({ type: 'string', value: 'tenantId', text: '学校租户id', dictCode: '' })
      this.superFieldList = fieldList
    }

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>